package com.siemens.industrial.web.mvc.service.partner;

import com.siemens.industrial.model.partner.DeviceState;
import com.siemens.industrial.utils.GlobalResponseCode;
import com.siemens.industrial.utils.SiemensException;
import com.siemens.industrial.web.mvc.dao.partner.PartnerDeviceStateDao;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * Created by qupen on 2016/8/31.
 * <p>
 * note: a device a record in or a a status a record in database, it's confused, need more think about.
 */
@Service
public class PartnerDeviceStateService {
    @Resource
    PartnerDeviceStateDao partnerDeviceStateDao;

//    public DeviceState getDeviceState(String tenantId, String deviceId, Date time) {
//        return partnerDeviceStateDao.getDeviceState(tenantId, deviceId, time);
//    }
//
//    public DeviceState getDeviceStateByDevice(String tenantId, String deviceId) {
//        return partnerDeviceStateDao.getDeviceStateByDevice(tenantId, deviceId);
//    }
//
//    public List<DeviceState> getDeviceStates(String tenantId) {
//        return partnerDeviceStateDao.getDeviceStates(tenantId);
//    }
//
//    public List<DeviceState> getDeviceStatesByDevice(String tenantId, String deviceId) {
//        return partnerDeviceStateDao.getDeviceStatesInDevice(tenantId, deviceId);
//    }
//
//    public List<DeviceState> getDeviceStatesByTime(String tenantId, Date time) {
//        return partnerDeviceStateDao.getDeviceStatesInTime(tenantId, time);
//    }

    @Transactional
    public void saveDeviceState(String tenantId, DeviceState deviceState) throws SiemensException {
            partnerDeviceStateDao.saveDeviceState(tenantId, deviceState);
    }

//    @Transactional
//    public void updateDeviceState(String tenantId, DeviceState deviceState) throws SiemensException {
//        if (partnerDeviceStateDao.getDeviceStateByDevice(tenantId, deviceState.getDeviceId()) != null) {
//            partnerDeviceStateDao.updateDeviceState(tenantId, deviceState);
//        } else {
//            throw new SiemensException(GlobalResponseCode.ERROR_STATE_NOT_EXISTED);
//        }
//    }

    public boolean isExist(String tenantId, String deviceId, long time,int statusType){
        return  partnerDeviceStateDao.isHaveTime(tenantId,deviceId,time,statusType);
    }
}
